package com.ihg.hiex.admin.dao.session;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Execute;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.ihg.hiex.entity.session.Session;
import com.ihg.hiex.entity.session.after.ReportGenerateStatus;
import com.ihg.hiex.entity.session.after.ReportSendStatus;
import com.ihg.hiex.entity.session.after.SessionReport;
import com.ihg.hiex.entity.user.Delegate;

/**
 * 
 * @author dan
 *
 */
@Dao("hibernate")
public interface SessionReportDao {
    
    /**
     * 
     * @param session
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND session = :session")
    public List<SessionReport> list(@Variable("session") Session session);
    
    /**
     * 
     * @param session
     * @param status
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND session = :session AND managerFinalReportStatus = :status")
    public List<SessionReport> listManagerReport(@Variable("session") Session session, @Variable("status") ReportGenerateStatus status);
    
    /**
     * 
     * @param session
     * @param status
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND session = :session AND peoplePlaningFinalReportStatus = :status")
    public List<SessionReport> listPplReport(@Variable("session") Session session, @Variable("status") ReportGenerateStatus status);
    
    /**
     * 
     * @param session
     * @param status
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND session = :session AND delegateFinalReportStatus = :status AND waveDelegateReport IS NOT NULL AND managerFinalReport IS NOT NULL")
    public List<SessionReport> listDelegateReport(@Variable("session") Session session, @Variable("status") ReportGenerateStatus status);
    
    /**
     * 
     * @param session
     * @param status
     * @param sendStatus
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND session = :session AND delegateFinalReportStatus = :status AND delegateSendStatus = :sendStatus")
    public List<SessionReport> listSendToDelegateReport(@Variable("session") Session session, @Variable("status") ReportGenerateStatus status, @Variable("sendStatus") ReportSendStatus sendStatus);
    
    /**
     * 
     * @param session
     * @param status
     * @param sendStatus
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND session = :session AND managerFinalReportStatus = :status AND managerSendStatus = :sendStatus")
    public List<SessionReport> listSendToManagerReport(@Variable("session") Session session, @Variable("status") ReportGenerateStatus status, @Variable("sendStatus") ReportSendStatus sendStatus);
    
    /**
     * 
     * @param generateStatus
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND peoplePlaningFinalReportStatus = :generateStatus")
    public List<SessionReport> listPplReport(@Variable("generateStatus") ReportGenerateStatus generateStatus);
    
    /**
     * 
     * @param generateStatus
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND managerFinalReportStatus = :generateStatus")
    public List<SessionReport> listManagerReport(@Variable("generateStatus") ReportGenerateStatus generateStatus);
    
    /**
     * 
     * @param generateStatus
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND delegateFinalReportStatus = :generateStatus")
    public List<SessionReport> listDelegateReport(@Variable("generateStatus") ReportGenerateStatus generateStatus);
    
    /**
     * 
     * @param session
     * @param delegate
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND session = :session AND delegate = :delegate")
    public SessionReport load(@Variable("session") Session session, @Variable("delegate") Delegate delegate);
    
    /**
     * 
     * @param delegate
     * @return
     */
    @Query("FROM SessionReport WHERE disabled = false AND delegate = :delegate")
    public SessionReport load(@Variable("delegate") Delegate delegate);
    
    /**
     * 
     * @param status
     * @param ids
     */
    @Execute("UPDATE SessionReport SET peoplePlaningFinalReportStatus = :status WHERE id in (:ids)")
    public void  updatePplReport(@Variable("status") ReportGenerateStatus status, @Variable("ids") List<Long> ids);
    
    /**
     * 
     * @param status
     * @param ids
     */
    @Execute("UPDATE SessionReport SET managerFinalReportStatus = :status WHERE id in (:ids)")
    public void  updateManagerReport(@Variable("status") ReportGenerateStatus status, @Variable("ids") List<Long> ids);
    
    /**
     * 
     * @param status
     * @param ids
     */
    @Execute("UPDATE SessionReport SET delegateFinalReportStatus = :status WHERE id in (:ids)")
    public void  updateDelegateReport(@Variable("status") ReportGenerateStatus status, @Variable("ids") List<Long> ids);
    
    /**
     * 
     * @param status
     * @param ids
     */
    @Execute("UPDATE SessionReport SET delegateSendStatus = :status WHERE id in(:ids)")
    public void updateSendDelegateReport(@Variable("status") ReportSendStatus status, @Variable("ids") List<Long> ids);
    
    /**
     * 
     * @param status
     * @param ids
     */
    @Execute("UPDATE SessionReport SET managerSendStatus = :status WHERE id in(:ids)")
    public void updateSendManagerReport(@Variable("status") ReportSendStatus status, @Variable("ids") List<Long> ids);

}
